import os

class CreateShot(object):
    def __init__(self):
        super(CreateShot, self).__init__()

        self.CONF_PATH=os.path.join(os.path.dirname(__file__),"config")
        self.ip=self.get_ip(self.CONF_PATH)


    def get_ip(self,config_path):
        data={}
        with open(config_path,'r',encoding='utf8') as r:
            data=eval(r.read())
        ip='\\\\'+data['path']
        print('ip:',ip)
        return ip

    def create_shot(self,data):
        """
        根据传来的信号生成目录结构
        :param data: {"project":xxx,"eps":xxx,"shot":xxx,"task":xxx}
        :return:
        """
        if data:
            project=data['project']
            eps=data['eps']
            shot=data['shot']
            pipeline=data['pipeline']
            print(self.ip,project,eps,shot)
            shot_path=os.path.join(self.ip,project,eps,shot,pipeline)
            print('create_shot:',shot_path)
            if not os.path.exists(shot_path):
                os.makedirs(shot_path)
            dir_list=['hip','geo','cam','abc','render','tex','sim']
            for i in dir_list:
                path=os.path.join(shot_path,i)
                if not os.path.exists(path):
                    os.makedirs(path)
            #最后将该镜头的信息写入
            shot_info_path=os.path.join(shot_path,'shot.info')
            with open(shot_info_path,'w',encoding='utf8') as w:
                w.write(str(data))

if __name__ == '__main__':
    c=CreateShot()
    data={"project":"MY","eps":"01","shot":"MY_05_02_006","pipeline":"efx_crowd"}
    c.create_shot(data)
